package com.sl.au.controller;

import com.sl.au.entity.Account;
import com.sl.au.service.AccountService;
import com.sl.au.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/ui/messEdit")
public class MessEditController extends BaseController {

    @Autowired
    AccountService accountService;
    @Autowired
    UserService userService;

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView index(HttpServletRequest request) {
        ModelAndView modelAndView = createLayoutView("messEdit/messEditindex");
        String name=request.getParameter("name");
        Account account= accountService.getAccountData(name);
        String userId=account.getId();
        String password=account.getPassword();
        String accountName=account.getAccountName();
        Boolean IsEnabled=account.getIsEnabled();
        modelAndView.addObject("id",userId);
        modelAndView.addObject("accountName",accountName);
        modelAndView.addObject("password",password);
        modelAndView.addObject("IsEnabled",IsEnabled);
        return modelAndView;
    }

//    @RequestMapping(value = "save", method = RequestMethod.POST)
//    public Map newPassword(HttpServletRequest request, @RequestBody Account account) {
//        Map map = new HashMap();
//        accountService.getRepository().save(account);
//        map.put("code", 0);
//        return map;
//    }

       //修改密码后保存
//    @RequestMapping(value = "save", method = RequestMethod.POST)
//    public Map saveUser(HttpServletRequest request) {
//        Map map = new HashMap();
//        map.put("code", -1);
//
//        map.put("code", 0);
//        return map;
//    }
}